#include "Player.h"
#include "../Graphic/GraphicManager.h"
#include "../Game/Level.h"
#include "../Game/Game.h"

//Update player
void cPlayer::Update(float lfTimeStep)
{
  //To control the speed of the player you can only move every 0.075ms
  mfElapsedTime += lfTimeStep;
  if (mfElapsedTime < 0.075) return;
  
  //Local variables that hold the next position
  unsigned int luiX = muiX;
  unsigned int luiY = muiY;

  //Check actions  
  if ((IsPressed(eIA_MoveLeft) ) && (luiX>0))
    luiX--;
   
  if ((IsPressed(eIA_MoveRight)) && (luiX<79))
    luiX++;

  //Check walls
  cLevel &lLevel = cLevel::Get();
  if (!lLevel.IsWall( luiX, luiY ))
  {
    muiX = luiX;
    muiY = luiY;
    mfElapsedTime = 0;
  }
}

//Render player
void cPlayer::Render()
{
  cGraphicManager::Get().SetColor(eLightGreen, eBlack);
  cGraphicManager::Get().WriteChar(muiX, muiY, mcSymbol);
}